home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_msql.idb / usr / freeware / msql / bin / setup_w3auth.z / setup_w3auth
Encoding:
Text File  |  1998-10-28  |  4.5 KB  |  255 lines

  1. #!/usr/freeware/msql/bin/lite
  2.  
  3.  
  4. /*
  5. ** This script sets up the required databases and tables for the W3-Auth
  6. ** access control system.
  7. */
  8.  
  9. echo("\n");
  10. echo("This script sets up the required databases and tables for the W3-Auth\n");
  11. echo("access control system.\n\n");
  12.  
  13. /*
  14. ** Create the empty databases
  15. */
  16.  
  17. echo ("Creating the empty database ...");
  18. if (system("/usr/freeware/msql/bin/msqladmin create w3-msql") != 0)
  19. {
  20.     fatal("\nError :  creating databases");
  21.     exit(1);
  22. }
  23.  
  24.  
  25. /*
  26. ** Connect to the server
  27. */
  28.  
  29. echo("\nW3-mSQL Setup\n-------------\n\n");
  30.  
  31. echo("Connecting to the mSQL server ... ");
  32. $sock = msqlConnect();
  33. if ($sock < 0)
  34. {
  35.     fatal("Error : $ERRMSG\n");
  36. }
  37. if (msqlSelectDB($sock,"w3-msql") < 0)
  38. {
  39.     fatal("Error : $ERRMSG\n");
  40. }
  41. echo ("connected.\n");
  42.  
  43.  
  44. /*
  45. ** Create the auth tables
  46. */
  47.  
  48. echo("Creating the namespace table ... ");
  49. if (msqlQuery($sock, " create table namespaces (
  50.             namespace    char(50),
  51.             descr        char(50))" ) < 0)
  52. {
  53.     fatal("Error : $ERRMSG\n");
  54. }
  55. echo("done.\n");
  56.  
  57.         
  58.  
  59. echo("Creating the areas table ... ");
  60. if (msqlQuery($sock, "create table areas (
  61.             name        char(50),
  62.             url        char(255),
  63.             namespace    char(25))" ) < 0)
  64. {
  65.     fatal("Error : $ERRMSG\n");
  66. }
  67. echo("done.\n");
  68.  
  69.  
  70.  
  71. echo("Creating the access control table ... ");
  72. if (msqlQuery($sock, "create table area_acl (
  73.             name        char(50),
  74.             offset        int,
  75.             group        char(20),
  76.             acl        char(50),
  77.             namespace    char(25))" ) < 0)
  78. {
  79.     fatal("Error : $ERRMSG\n");
  80. }
  81. echo("done.\n");
  82.  
  83.  
  84. echo("Creating the access control table index ... ");
  85. if (msqlQuery($sock, "create index idx1 on area_acl (name)") < 0)
  86. {
  87.     fatal("Error : $ERRMSG\n");
  88. }
  89. echo("done.\n");
  90.  
  91.  
  92.  
  93. echo("Creating the users table ... ");
  94. if (msqlQuery($sock, "create table users (
  95.             namespace    char(25),
  96.             uname        char(20),
  97.             passwd        char(20),
  98.             full_name     char(50))") < 0)
  99. {
  100.     fatal("Error : $ERRMSG\n");
  101. }
  102. echo("done.\n");
  103.  
  104.  
  105. echo("Creating the users table index ... ");
  106. if (msqlQuery($sock, "create unique index idx1 on users (
  107.             namespace,
  108.             uname)") < 0)
  109. {
  110.     fatal("Error : $ERRMSG\n");
  111. }
  112. echo("done.\n");
  113.  
  114.  
  115. echo("Creating the namespace perms table ... ");
  116. if (msqlQuery($sock, "create table perms (
  117.             uname        char(25),
  118.             namespace    char(25),
  119.             level        int)") < 0)
  120. {
  121.     fatal("Error : $ERRMSG\n");
  122. }
  123. echo("done.\n");
  124.  
  125.  
  126.  
  127. echo("Creating the namespace perms table index ... ");
  128. if (msqlQuery($sock, "create index idx1 on perms ( uname )") < 0)
  129. {
  130.     fatal("Error : $ERRMSG\n");
  131. }
  132. echo("done.\n");
  133.  
  134.  
  135.  
  136.  
  137. echo("Creating the group_members table ... ");
  138. if (msqlQuery($sock, "create table group_members (
  139.             namespace    char(25),
  140.             group        char(20),
  141.             uname        char(20))") < 0)
  142. {
  143.     fatal("Error : $ERRMSG\n");
  144. }
  145. echo("done.\n");
  146.  
  147.  
  148.  
  149. echo("Creating the group_members table index ... ");
  150. if (msqlQuery($sock, "create index idx1 on group_members (
  151.             namespace,
  152.             group)") < 0)
  153. {
  154.     fatal("Error : $ERRMSG\n");
  155. }
  156. echo("done.\n");
  157.  
  158.  
  159.  
  160.  
  161. echo("Creating the groups table ... ");
  162. if (msqlQuery($sock, "create table groups (
  163.             namespace    char(25),
  164.             group        char(20),
  165.             descr        char(50))") < 0)
  166. {
  167.     fatal("Error : $ERRMSG\n");
  168. }
  169. echo("done.\n");
  170.  
  171.  
  172. echo("Creating the groups table index ... ");
  173. if (msqlQuery($sock, "create index idx1 on groups (
  174.             namespace,
  175.             group)") < 0)
  176. {
  177.     fatal("Error : $ERRMSG\n");
  178. }
  179. echo("done.\n");
  180.  
  181.  
  182.  
  183.  
  184.  
  185. echo("Creating the group_admin table ... ");
  186. if (msqlQuery($sock, "create table group_admin (
  187.             namespace    char(25),
  188.             group        char(20),
  189.             uname        char(20))") < 0)
  190. {
  191.     fatal("Error : $ERRMSG\n");
  192. }
  193. echo("done.\n");
  194.  
  195.  
  196.  
  197. echo("Creating the group_admin table index ... ");
  198. if (msqlQuery($sock, "create index idx1 on group_admin (
  199.             namespace,
  200.             group)") < 0)
  201. {
  202.     fatal("Error : $ERRMSG\n");
  203. }
  204. echo("done.\n");
  205.  
  206.  
  207.  
  208. /*
  209. ** Populate the data with some bootstrap info
  210. */
  211.  
  212.  
  213. echo("Creating the W3-auth administrative namespace ... ");
  214. if (msqlQuery($sock, "insert into namespaces values 
  215.         ('SuperUser', 'W3-mSQL Administrators')") < 0)
  216. {
  217.     fatal("Error : $ERRMSG\n");
  218. }
  219. echo("done.\n");
  220.  
  221.  
  222. /*
  223. ** Add a "super user" to the w3-msql auth tables
  224. */
  225.  
  226. echo ("\nAdding a \"super user\" to the w3-msql auth tables\n\n");
  227. echo ("Username  : ");
  228. $user = readln($stdin);
  229. $user = chop($user);
  230. echo ("Full name : ");
  231. $fullname = readln($stdin);
  232. $fullname = chop($fullname);
  233. echo ("Password  : ");
  234. $passwd = readln($stdin);
  235. $passwd = chop($passwd);
  236.  
  237. $passwd = crypt($passwd,"AA");
  238.  
  239.  
  240. if (msqlQuery($sock,"insert into users values 
  241.     ('SuperUser', '$user','$passwd','$fullname')") < 0)
  242. {
  243.     fatal("Error : $ERRMSG\n");
  244. }
  245.  
  246. if (msqlQuery($sock,"insert into perms values 
  247.     ('$user','SuperUser',255)") < 0)
  248. {
  249.     fatal("Error : $ERRMSG\n");
  250. }
  251.  
  252. msqlClose($sock);
  253.  
  254. echo("Done.\n\nSetup of W3-mSQL is complete\n\n");
  255.